home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / VideoToolboxSources / HideMenuBar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-10  |  3.9 KB  |  146 lines  |  [TEXT/KAHL]

  1. /*
  2. HideMenuBar.c
  3.  
  4. Based on:
  5.  
  6. "Code gadgets: Hiding the menu bar", THINKin' CaP, 1(2):28-29, Fall 1990.
  7. Copyright © 1991 SPLAsh Resources.
  8.  
  9. and
  10.  
  11. Symantec THINK Reference 2, "How to Hide the MenuBar".
  12.  
  13. HISTORY:
  14. 2/28/91 dgp added to VideoToolbox
  15. 8/24/91    dgp    Made compatible with THINK C 5.
  16. 1/25/93 dgp removed obsolete support for THINK C 4.
  17. 1/25/93    dgp Replaced SysEqu.h by LoMem.h and changed program accordingly.
  18. 2/23/93    dgp    Call CopyQuickDrawGlobals to make sure qd is valid.
  19. 2/27/93    dgp Edited the code and comments, partly copying from THINK Reference's
  20.             suggestion for how to do this. This was prompted by David Brainard's
  21.             report that these routines were crashing when called within the
  22.             MatLab environment. The main changes are to also call
  23.             CalcVisBehind() after restoring, and to use DiffRgn
  24.             to restore by cutting the menu bar back out of the desktop
  25.             instead of restoring by copying from a saved copy of the region. 
  26. 3/3/93    dgp    Added SquareCorners and RestoreCorners, with support for 1-bit quickdraw.
  27. */
  28. #include "VideoToolbox.h"
  29. #include <Menus.h>
  30. #if THINK_C
  31.     #include <LoMem.h>
  32. #else
  33.     short MBarHeight : 0xBAA;
  34. #endif
  35.  
  36. static short oldMBarHeight;                    // Pixel height of the menu bar
  37. static RgnHandle mBarRgn=NULL;                // Region encompassing the menu bar
  38. static RgnHandle cornerRgn[MAX_SCREENS];
  39.  
  40. void HideMenuBar(void)
  41. {
  42.     Rect r;
  43.     
  44.     if (MBarHeight>0) {
  45.         mBarRgn=NewRgn();
  46.         CopyQuickDrawGlobals();                // Make sure qd is valid
  47.         r=qd.screenBits.bounds;
  48.         r.bottom=r.top+MBarHeight;
  49.         RectRgn(mBarRgn,&r);
  50.         oldMBarHeight=MBarHeight;
  51.         MBarHeight=0;
  52.         UnionRgn(GetGrayRgn(),mBarRgn,GetGrayRgn());
  53.         PaintOne(NULL,mBarRgn);
  54.         CalcVisBehind((WindowPeek)FrontWindow(),mBarRgn);
  55.     }
  56. }
  57.  
  58. void ShowMenuBar(void)
  59. {
  60.     if(MBarHeight==0 && mBarRgn!=NULL){
  61.         MBarHeight=oldMBarHeight;
  62.         DiffRgn(GetGrayRgn(),mBarRgn,GetGrayRgn());
  63.         DrawMenuBar();
  64.         CalcVisBehind((WindowPeek)FrontWindow(),mBarRgn);
  65.         DisposeRgn(mBarRgn);
  66.         mBarRgn=NULL;
  67.     }
  68. }
  69.  
  70. void SquareCorners(GDHandle device)
  71. // Extend GrayRgn to include this screen's corners, which otherwise might be rounded off.
  72. // If NULL then applies to all screens.
  73. {
  74.     int i;
  75.     Rect r;
  76.     long quickDraw;
  77.     
  78.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  79.     if(quickDraw<gestalt8BitQD){
  80.         i=0;
  81.         CopyQuickDrawGlobals();                // Make sure qd is valid
  82.         r=qd.screenBits.bounds;
  83.         r.top+=MBarHeight;
  84.     }else{
  85.         if(device==NULL){
  86.             for(i=0;GetScreenDevice(i)!=NULL;i++)SquareCorners(GetScreenDevice(i));
  87.             return;
  88.         }
  89.         i=GetScreenIndex(device);
  90.         if(i>=MAX_SCREENS)return;
  91.         r=(*device)->gdRect;
  92.         if(device==GetMainDevice())r.top+=MBarHeight;
  93.     }
  94.     cornerRgn[i]=NewRgn();
  95.     RectRgn(cornerRgn[i],&r);
  96.     DiffRgn(cornerRgn[i],GetGrayRgn(),cornerRgn[i]);
  97.     if(EmptyRgn(cornerRgn[i]))return;
  98.     UnionRgn(GetGrayRgn(),cornerRgn[i],GetGrayRgn());
  99.     PaintBehind((WindowPeek)FrontWindow(),cornerRgn[i]);
  100.     CalcVisBehind((WindowPeek)FrontWindow(),cornerRgn[i]);
  101. }
  102.  
  103. void RestoreCorners(GDHandle device)
  104. // Restore rounding to this screen.
  105. // If NULL then applies to all screens.
  106. {
  107.     int i;
  108.     long quickDraw;
  109.     
  110.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  111.     if(quickDraw<gestalt8BitQD){
  112.         i=0;
  113.     }else{
  114.         if(device==NULL){
  115.             for(i=0;GetScreenDevice(i)!=NULL;i++)RestoreCorners(GetScreenDevice(i));
  116.             return;
  117.         }
  118.         i=GetScreenIndex(device);
  119.         if(i>=MAX_SCREENS)return;
  120.     }
  121.     if(cornerRgn[i]!=NULL){
  122. //        CopyQuickDrawGlobals();            // Make sure qd is valid.
  123. //        FillRgn(cornerRgn[i],qd.black);    // don't know what port it belongs to
  124.         DiffRgn(GetGrayRgn(),cornerRgn[i],GetGrayRgn());
  125.         DisposeRgn(cornerRgn[i]);
  126.         cornerRgn[i]=NULL;
  127.     }
  128. }
  129.  
  130. void UnclipScreen(GDHandle device)
  131. {
  132.     long quickDraw;
  133.  
  134.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  135.     if(quickDraw<gestalt8BitQD || device==GetMainDevice())HideMenuBar();
  136.     SquareCorners(device);
  137. }
  138.  
  139. void RestoreScreenClipping(GDHandle device)
  140. {
  141.     long quickDraw;
  142.  
  143.     RestoreCorners(device);
  144.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  145.     if(quickDraw<gestalt8BitQD || device==GetMainDevice())ShowMenuBar();
  146. }